package com.briup.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.briup.bean.User;
import com.briup.common.exception.UserException;
import com.briup.service.IUserService;
import com.briup.service.impl.IUserServiceImpl;

@WebServlet("/ForgetPwd2Ser")
public class ForgetPwd2Ser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		String password1=request.getParameter("password1");
		HttpSession session=request.getSession();
		String username=(String) session.getAttribute("username");
		
		IUserService service=new IUserServiceImpl();
		try {
			User u=service.getUserByName(username);
			u.setUsername(username);
			u.setPassword(password1);
			service.updateUserInfo(u);
			request.setAttribute("msg", "密码已重置！请");
			request.getRequestDispatcher("/forgetPassword3.jsp")
				.forward(request, response);
		} catch (UserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
